package com.huluobo.a2307douyindemo.startLive

import android.util.Log
import com.huluobo.a2307douyindemo.databinding.ActivityStartLiveBinding
import com.huluobo.lib_base.mvvm.BaseActivity
import com.tencent.live2.V2TXLiveCode.V2TXLIVE_ERROR_INVALID_LICENSE
import com.tencent.live2.V2TXLiveDef
import com.tencent.live2.V2TXLivePusher
import com.tencent.live2.impl.V2TXLivePusherImpl


class StartLiveActivity : BaseActivity<ActivityStartLiveBinding, StartLiveViewModel>() {

    override fun initData() {
    }

    override fun initView() {
        //推流工具,设置为RTMP协议
        val mLivePusher: V2TXLivePusher = V2TXLivePusherImpl(this, V2TXLiveDef.V2TXLiveMode.TXLiveMode_RTMP)
        // 启动本地摄像头预览
        mLivePusher.setRenderView(binding.pusherTxCloudView)
        mLivePusher.startCamera(true)
        mLivePusher.startMicrophone()

        binding.startLiveBtn.setOnClickListener {
            // 根据推流协议传入对应的 URL 即可启动推流， RTMP 协议以 rtmp:// 开头，该协议不支持连麦
            val url =
                "rtmp://220434.push.tlivecloud.com/live/123?txSecret=24901363577f081ab08db66b59cee9c5&txTime=68E725D4"
            val ret = mLivePusher.startPush(url)
            if (ret == V2TXLIVE_ERROR_INVALID_LICENSE) {
                Log.i("TagA", "startRTMPPush: license 校验失败")
            }
        }

        binding.startLiveStopBtn.setOnClickListener {
            mLivePusher.stopPush()
        }
    }
}